include $(TOPDIR)/rules.mk
PKG_NAME:=meterserv
PKG_VERSION:=0.4.0
PKG_RELESE:=1
DOCROOT=/home/www/servers/meterserv

include $(INCLUDE_DIR)/package.mk

define Package/meterserv
	SECTION:=utils
	CATEGORY:=Utilities
	TITLE:=Meterserv - Utility meter monitoring system.
	DEPENDS:=+libusb \
		+lighttpd +lighttpd-mod-cgi +lighttpd-mod-accesslog \
		#+perl +perl-dbi +perlbase-cgi +perlbase-dynaloader \
		#+perlbase-config +perlbase-autoloader \
		#+perlbase-file

endef


define Package/meterserv/description
	Utility meter monitoring system.
endef


define Build/Prepare
	echo "Build/Prepare"
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) -rf ./src/* $(PKG_BUILD_DIR)
endef

define Build/Configure
	echo "Build/Configure"
# No configuration necessary
endef    

define Build/Compile
	echo "Build/Compile"
	$(MAKE) -C $(PKG_BUILD_DIR) \
	$(TARGET_CONFIGURE_OPTS) \
	CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include" \
	LDFLAGS="-L$(STAGING_DIR)/usr/lib"
endef

define Package/meterserv/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_DIR) $(1)/etc
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DIR) $(1)$(DOCROOT)
	$(INSTALL_DIR) $(1)$(DOCROOT)/cgi-bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/metermond \
			$(PKG_BUILD_DIR)/metermonctrl \
			$(1)/usr/bin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/lighttpd.conf.meterserv \
			$(1)/etc/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/metermon \
			$(1)/etc/init.d/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/www/*.html \
			$(1)$(DOCROOT)
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/www/images/* \
			$(1)$(DOCROOT)
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/* \
			$(1)$(DOCROOT)
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/perl/*.cgi \
			$(PKG_BUILD_DIR)/perl/*.pm \
			$(PKG_BUILD_DIR)/perl/meters.db.example \
			$(PKG_BUILD_DIR)/scripts/update_meterserv_package.sh \
			$(PKG_BUILD_DIR)/sysupdate.cgi \
			$(1)$(DOCROOT)/cgi-bin
endef

$(eval $(call BuildPackage,meterserv))
